package cn.lili.modules.goods.entity.vos;

import cn.hutool.core.bean.BeanUtil;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.utils.CurrencyUtil;
import cn.lili.modules.distribution.entity.dos.Distribution;
import cn.lili.modules.goods.entity.dos.GoodsSku;
import cn.lili.modules.system.entity.enums.SettingEnum;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;

/**
 * 商品规格VO
 *
 * @author paulG
 * @since 2020-02-26 23:24:13
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class GoodsSkuVO extends GoodsSku {

    private static final long serialVersionUID = -7651149660489332344L;

    @ApiModelProperty(value = "规格列表")
    private List<SpecValueVO> specList;

    @ApiModelProperty(value = "商品图片")
    private List<String> goodsGalleryList;

    @ApiModelProperty(value = "规格参数")
    private String specParameter;

    @ApiModelProperty(value = "自己买省*钱/立即推广赚*钱")
    private double omitGreenScore = 0D;

    @ApiModelProperty(value = "促销原价")
    @TableField(exist = false)
    private Double promotionOriginalPrice;

    public GoodsSkuVO(GoodsSku goodsSku) {
        BeanUtil.copyProperties(goodsSku, this);
    }

    /**
     * 构建omitGreenScore
     * */
    public void initOmitGreenScore(Distribution currentDistribution, GoodsSkuVO goodsSkuDetail, Map<SettingEnum, com.alibaba.fastjson.JSONObject> settings){
        if(currentDistribution!=null){
            if(Boolean.TRUE.equals(goodsSkuDetail.getIsGreenGoods())) {
                //比例
                double number = CurrencyUtil.div(settings.get(SettingEnum.GREEN_GOODS).getDouble("lowerProportion"),100);
                //优惠金额
                goodsSkuDetail.setOmitGreenScore(CurrencyUtil.mul(goodsSkuDetail.getGreenScore(),number));
            }else{
                //比例
                double number = CurrencyUtil.div(settings.get(SettingEnum.NOT_GREEN_GOODS).getDouble("lowerProportion"),100);
                //优惠金额
                goodsSkuDetail.setOmitGreenScore(CurrencyUtil.mul(goodsSkuDetail.getGreenScore(),number));
            }
        }
    }
}

